package com.jdz.gxq.info.admin.estate.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.estate.bo.Estate;
import com.jdz.gxq.info.admin.estate.form.AddEstateForm;
import com.jdz.gxq.info.admin.estate.service.EstateService;
import com.jdz.gxq.info.common.action.CommonAction;

public class AddEstateAction extends CommonAction {

	private EstateService estateService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		AddEstateForm addEstateFrom = (AddEstateForm) form;
		
		Estate estate = addEstateFrom.getEstate();
		
		// estate名重复验证(其他后台逻辑验证也类似处理)
		if (!estateService.checkEstateName(estate, 1)) {
			ActionMessages messages = new ActionMessages();
			messages.add("estate.enterpriseName", new ActionMessage("error.estateNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}
		
		estate.setModifiedBy(getUserId(request));
		estateService.insertEstate(estate);

		return mapping.findForward("success");
	}

	public void setEstateService(EstateService estateService) {
		this.estateService = estateService;
	}
}

